﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ERP.Manager.Core;
using ERP.Manager.DataEntity;
using ERP.Manager.DataProvider;
using ERP.Manager.DataHelper;
using System.Data.SqlClient;
using System.Data;
namespace ERP.Manager.SQLServerProvider
{
    public class ECS_goods_typeinfoRepository : IECS_goods_typeinfoRepository
    {
        private ECS_attributeinfoRepository ecs_attributeinforepository = new ECS_attributeinfoRepository();
        #region 分页查询所有商品类型的方法
        public List<ECS_goods_typeinfo> all_ecs_goods_typeinfo_page(int pagecount)
        {
            List<ECS_goods_typeinfo> list = new List<ECS_goods_typeinfo>();
            SqlDataReader read = SQLHelper.ExecuteReader(CommandType.Text, ERPSQL.ALL_ECS_GOODS_TYPEINFO_PAGE,
                new SqlParameter("@pagecount", pagecount));
            try
            {
                while (read.Read())
                {
                    ECS_goods_typeinfo goods = new ECS_goods_typeinfo();
                    goods.cat_id = int.Parse(read["cat_id"].ToString());
                    goods.cat_name = read["cat_name"].ToString();
                    goods.cat_enabled = int.Parse(read["cat_enabled"].ToString());
                    goods.attr_group = read["attr_group"].ToString();
                    goods.attributecount = ecs_attributeinforepository.all_ecs_attributeinfo_cat_id_count(int.Parse(read["cat_id"].ToString()));
                    list.Add(goods);
                }
                read.Close();
            }
            catch (Exception)
            {
                read.Close();
            }
            finally
            {
                read.Dispose();
            }
            return list;
        }
        #endregion

        #region 查询所有商品类型的方法
        public List<ECS_goods_typeinfo> all_ecs_goods_typeinfo()
        {
            List<ECS_goods_typeinfo> list = new List<ECS_goods_typeinfo>();
            SqlDataReader read = SQLHelper.ExecuteReader(CommandType.Text, ERPSQL.ALL_ECS_GOODS_TYPEIFO);
            try
            {
                while (read.Read())
                {
                    ECS_goods_typeinfo goods = new ECS_goods_typeinfo();
                    goods.cat_id = int.Parse(read["cat_id"].ToString());
                    goods.cat_name = read["cat_name"].ToString();
                    goods.cat_enabled = int.Parse(read["cat_enabled"].ToString());
                    goods.attr_group = read["attr_group"].ToString();
                    list.Add(goods);
                }
                read.Close();
            }
            catch (Exception)
            {
                read.Close();
            }
            finally
            {
                read.Dispose();
            }
            return list;
        }
        #endregion

        #region 添加商品品牌的方法
        public int add_ecs_goods_typeinfo(ECS_goods_typeinfo goodstype)
        {
            int rowcount = SQLHelper.ExecuteNonQuery(CommandType.Text, ERPSQL.ADD_ECS_GOODS_TYPEINFO,
                new SqlParameter("@cat_name", goodstype.cat_name),
                new SqlParameter("@cat_enabled", goodstype.cat_enabled),
                new SqlParameter("@attr_group", goodstype.attr_group));
            return rowcount;
        }
        #endregion

        #region 根据商品类型编号查询商品类型信息的方法
        public ECS_goods_typeinfo detail_ecs_goods_typeinfo(int cat_id)
        {
            ECS_goods_typeinfo goods = new ECS_goods_typeinfo();
            SqlDataReader read = SQLHelper.ExecuteReader(CommandType.Text, ERPSQL.DETAIL_ECS_GOODS_TYPEINFO,
                new SqlParameter("@cat_id", cat_id));
            try
            {
                while (read.Read())
                {
                    goods.cat_id = int.Parse(read["cat_id"].ToString());
                    goods.cat_name = read["cat_name"].ToString();
                    goods.cat_enabled = int.Parse(read["cat_enabled"].ToString());
                    goods.attr_group = read["attr_group"].ToString();
                }
                read.Close();
            }
            catch (Exception)
            {
                read.Close();
            }
            finally
            {
                read.Dispose();
            }
            return goods;
        }
        #endregion

        #region 修改商品类型的方法
        public int update_ecs_goods_typeinfo(ECS_goods_typeinfo goodstype)
        {
            int rowcount = SQLHelper.ExecuteNonQuery(CommandType.Text, ERPSQL.UPDATE_ECS_GOODS_TYPEINFO,
                new SqlParameter("@cat_id", goodstype.cat_id),
                new SqlParameter("@cat_name", goodstype.cat_name),
               new SqlParameter("@cat_enabled", goodstype.cat_enabled),
               new SqlParameter("@attr_group", goodstype.attr_group));
            return rowcount;
        }
        #endregion

        #region 删除商品类型的方法
        public int delete_ecs_goods_typeinfo(int cat_id)
        {
            int rowcount = SQLHelper.ExecuteNonQuery(CommandType.Text, ERPSQL.DELETE_ECS_GOODS_TYPEINFO,
                new SqlParameter("@cat_id", cat_id));
            return rowcount;
        }
        #endregion

        #region 查询所有的商品类型的方法
        public List<ECS_goods_typeinfo> all_ecs_goods_typeinfo_cat_name()
        {
            List<ECS_goods_typeinfo> list = new List<ECS_goods_typeinfo>();
            SqlDataReader read = SQLHelper.ExecuteReader(CommandType.Text, ERPSQL.ALL_ECS_GOODS_TYPEINFO_CAT_NAME);
            try
            {
                while (read.Read())
                {
                    ECS_goods_typeinfo goods = new ECS_goods_typeinfo();
                    goods.cat_id = int.Parse(read["cat_id"].ToString());
                    goods.cat_name = read["cat_name"].ToString();
                    goods.cat_enabled = int.Parse(read["cat_enabled"].ToString());
                    goods.attr_group = read["attr_group"].ToString();
                    list.Add(goods);
                }
                read.Close();
            }
            catch (Exception)
            {
                read.Close();
            }
            finally
            {
                read.Dispose();
            }
            return list;
        }
        #endregion
    }
}
